package com.atguigu.ssyx;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @作者:胡树苑
 * @时间:2025/9/21 19:47
 */
//计算完成回调
//whenComplete：是执行当前任务的线程执行继续执行 whenComplete 的任务。
public class CompletableFutureDemo3 {
    public static void main(String[] args) {
        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        System.out.println("main begin");
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程:" + Thread.currentThread().getName());
            int value =1024/0;
            System.out.println("value:" + value);
            return value;
        }, executorService).whenComplete(
                (r,e)->{
                    System.out.println("whenComplete:"+r);
                    System.out.println("exception:"+e);
                }
        );

        System.out.println("main end");
    }
}
